home *** CD-ROM | disk | FTP | other *** search
- Attribute VB_Name = "MailSupport"
- Option Explicit
-
- '<Constant>--------------------------------------------
- Public Const ciAddAddress As Integer = 0
- Public Const ciAddressProperties As Integer = 1
-
- Public AttachmentStream As String
- '</Constant>-------------------------------------------
-
- '------------------------------------------------------
- '<Purpose> reads an encoded file into a data stream
- ' in preparation to send it
- '------------------------------------------------------
- Public Function ReadTempFile(DestinationFileName As String) As Boolean
- Dim hFile As Integer
- Dim Remainder As Integer
- Dim BlockCount As Long
- Dim FileSize As Long
- Dim NumberBlocks As Long
- Dim Buffer As String
-
- Const MaxBlockSize As Integer = 32767
-
- '---- Obtain a free file number
- hFile = FreeFile
-
- '---- clear the attachment data stream
- AttachmentStream = ""
-
- On Error GoTo BadRead
- '---- Who cares which control you passed, then both have the same property names
- Open DestinationFileName For Binary Access Read As #hFile
-
- '---- read in blocks of data from the file
- NumberBlocks = LOF(hFile) \ MaxBlockSize
- Remainder = LOF(hFile) Mod MaxBlockSize
- For BlockCount = 1 To NumberBlocks
- Buffer = Space(MaxBlockSize)
- Get #hFile, , Buffer
- AttachmentStream = AttachmentStream & Buffer
- Next
-
- '---- read in any remainder from the file
- If Remainder Then
- Buffer = Space(Remainder)
- Get #hFile, , Buffer
- AttachmentStream = AttachmentStream & Buffer
- End If
-
- Close #hFile
-
- '---- processed ok
- ReadTempFile = True
- On Error GoTo 0
- Exit Function
-
- '---- Add specific error handling here
- BadRead:
- ReadTempFile = False
- On Error GoTo 0
-
- End Function
- Public Function ExtractMessageBody(FileName As String) As String
- Dim CharPos As Integer
- Dim hFile As Integer
- Dim Remainder As Integer
- Dim BlockCount As Long
- Dim FileSize As Long
- Dim NumberBlocks As Long
- Dim Buffer As String
- Dim Temp As String
- Dim MimeInfo As String
- Dim Boundary As String
-
- Const MaxBlockSize As Integer = 32767
-
- '---- Obtain a free file number
- hFile = FreeFile
-
- On Error GoTo BadRead
- '---- Who cares which control you passed, then both have the same property names
- Open FileName For Binary Access Read As #hFile
-
- '---- read in blocks of data from the file
- NumberBlocks = LOF(hFile) \ MaxBlockSize
- Remainder = LOF(hFile) Mod MaxBlockSize
- For BlockCount = 1 To NumberBlocks
- Buffer = Space(MaxBlockSize)
- Get #hFile, , Buffer
- Temp = Temp & Buffer
- Next
-
- '---- read in any remainder from the file
- If Remainder Then
- Buffer = Space(Remainder)
- Get #hFile, , Buffer
- Temp = Temp & Buffer
- End If
-
- Close #hFile
-
- ExtractMessageBody = Temp
- On Error GoTo 0
- Exit Function
-
- '---- now check the temp string for an encoded attachment
- CharPos = InStr(Temp, "Content-Type:")
- If (CharPos = 0) Then
- ExtractMessageBody = ""
- Exit Function
- End If
-
- '---- try to determine destination file name
- MimeInfo = Mid$(Temp, CharPos)
- CharPos = InStr(MimeInfo, "; boundary=")
- If (CharPos > 0) Then
- Boundary = Mid(MimeInfo, CharPos + Len("; boundary=") + 1, CharPos + 100)
- CharPos = InStr(Boundary, Chr$(34))
- Boundary = left(Boundary, CharPos - 1)
- Else
- ExtractMessageBody = ""
- Exit Function
- End If
- CharPos = InStr(MimeInfo, "Content-Type: text/plain;")
- If CharPos Then
- MimeInfo = Mid(MimeInfo, CharPos)
- CharPos = InStr(MimeInfo, vbCrLf & vbCrLf)
- MimeInfo = Mid(MimeInfo, CharPos + 4)
- CharPos = InStr(MimeInfo, Boundary)
- ExtractMessageBody = left(MimeInfo, CharPos - 1)
- End If
-
- '---- checked ok
- On Error GoTo 0
- Exit Function
-
- '---- Add specific error handling here
- BadRead:
- ExtractMessageBody = ""
- On Error GoTo 0
-
- End Function
- '---------------------------------------------------------
- '<Purpose> checks a message to see if it is an attachment
- '---------------------------------------------------------
- Public Function CheckForAttachment(FileName As String, SentFile As String, MessageNumber As Integer) As Boolean
- Dim CharPos As Integer
- Dim hFile As Integer
- Dim Remainder As Integer
- Dim BlockCount As Long
- Dim FileSize As Long
- Dim NumberBlocks As Long
- Dim Buffer As String
- Dim Temp As String
- Dim MimeInfo As String
-
- Const MaxBlockSize As Integer = 32767
-
- '---- Obtain a free file number
- hFile = FreeFile
-
- On Error GoTo BadRead
- '---- Who cares which control you passed, then both have the same property names
- Open FileName For Binary Access Read As #hFile
-
- '---- read in blocks of data from the file
- NumberBlocks = LOF(hFile) \ MaxBlockSize
- Remainder = LOF(hFile) Mod MaxBlockSize
- For BlockCount = 1 To NumberBlocks
- Buffer = Space(MaxBlockSize)
- Get #hFile, , Buffer
- Temp = Temp & Buffer
- Next
-
- '---- read in any remainder from the file
- If Remainder Then
- Buffer = Space(Remainder)
- Get #hFile, , Buffer
- Temp = Temp & Buffer
- End If
-
- Close #hFile
-
- '---- now check the temp string for an encoded attachment
- CharPos = InStr(Temp, "Content-Type:")
- If (CharPos = 0) Then
- CheckForAttachment = False
- Exit Function
- End If
-
- '---- try to determine destination file name
- MimeInfo = Mid$(Temp, CharPos)
- CharPos = InStr(MimeInfo, "; name=")
- If (CharPos > 0) Then
- SentFile = Mid(MimeInfo, CharPos + Len("; name=") + 1, CharPos + 100)
- CharPos = InStr(SentFile, """")
- SentFile = "c:\" & left(SentFile, CharPos - 1)
- Else
- CheckForAttachment = False
- Exit Function
- End If
-
- '---- checked ok
- CheckForAttachment = True
- On Error GoTo 0
- Exit Function
-
- '---- Add specific error handling here
- BadRead:
- CheckForAttachment = False
- On Error GoTo 0
- End Function
-